package ar.com.ford.it.fullEconomics.persistence.dao.query;

import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesg01Plant;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp01Part;
import com.ford.it.persistence.impl.toplink.CustomExpressionFactory;

public class PartsUsageFindQuery implements CustomExpressionFactory {

    public Expression createExpression(ExpressionBuilder builder,
                                       Object[] parameters) {
        Expression exp = null;
        Teesp01Part part = (Teesp01Part) parameters[0];
        
        Teesg01Plant pplant = part.getEesp01PlantCodeC();
        String pprefix = part.getEesp01PartPrefixCodeC();
        String pbase = part.getEesp01PartBaseCodeC();
        String psuffix = part.getEesp01PartSuffixCodeC();

        exp = builder.get("eesp07PlantCodeC").equal(pplant);
        
        // LSPARACI : suprimi lo siguiente
        //exp = exp.and(builder.get("teesp01Part").get("eesp01PartPrefixCodeC").equal(pprefix));
        //exp = exp.and(builder.get("teesp01Part").get("eesp01PartBaseCodeC").equal(pbase));
        //exp = exp.and(builder.get("teesp01Part").get("eesp01PartSuffixCodeC").equal(psuffix));
        // reemplazado por:
        
        exp = exp.and(builder.get("eesp07PartPrefixCodeC").equal(pprefix));
        exp = exp.and(builder.get("eesp07PartBaseCodeC").equal(pbase));
        exp = exp.and(builder.get("eesp07PartSuffixCodeC").equal(psuffix));
         
        // end LSPARACI
        
        
        return exp;
    }

}
